<template>
    <div>
        <table class="table table-bordered">
            <tr>
                <td>用户名</td>
                <td>
                    <input type="text" v-model="state.name">
                </td>
            </tr>

            <tr>
                <td>密码</td>
                <td>
                    <input type="password" v-model="state.pwd">
                </td>
            </tr>

            <tr align="center">

                <td colspan="2">
                    <input type="button" value="登录" @click="login">
                </td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import axios from 'axios';
import { useStore } from '../stores/user';
let store = useStore()
let router = useRouter();
let route = useRoute();

let data: any = reactive({
    state: {
        name: '',
        pwd: '',
    },
});

let { state } = toRefs(data);
const login = () => {
    if (state.value.name == "") {
        alert('请输入用户名');
        return;
    }
    if (state.value.pwd == "") {
        alert('请输入密码');
        return;
    }

    let obj = {
        name: state.value.name,
        pwd: state.value.pwd
    }

    axios({
        url: '/api/Login/Dneg',
        method: 'get',
        params: obj
    }).then(res => {
        console.log(res);
        if(res.data.data == -1)
        {
            alert('用户名不存在');
            return;
        }
         if(res.data.data == -2)
        {
            alert('密码错误');
            return;
        }
        //存到pinia里面
        store.useinfo = res.data.data;
    })
}
</script>

<style scoped></style>